/*
 * @Author: vera_min vera_min@163.com
 * @Date: 2024-12-20 17:55:23
 * @LastEditors: vera_min vera_min@163.com
 * @LastEditTime: 2025-08-26 15:24:45
 * @FilePath: /mail-project/src/api/email/index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios, { CancelTokenSource } from 'axios';
import { get, post, del, put } from '/@/utils/request';

let cancelTokenSource: CancelTokenSource | null = null;

const getDetail = (id: any, params = {}) => {
	// 如果存在之前的请求，则取消它
	if (cancelTokenSource) {
		cancelTokenSource.cancel('Previous request canceled');
	}
	// 创建一个新的cancel token source
	cancelTokenSource = axios.CancelToken.source();
	return get(`/email/api/email/getInfo/${id}`, params, { cancelToken: cancelTokenSource.token });
}

export default {
	folder: {
		getList: (account: string) => get(`/email/api/email/folderList/${account}`, {}),
		getEmailList: () => get(`/email/api/email/list`, {}),
		getEmailNumData: (params: object) => get(`/email/api/email/dateScopeList`, params),
		addItem: (params: object) => post(`/email/api/email/addFolder`, params),
	},
	email: {
		getList: (params: object) => get(`/email/api/email/folderMsgList`, params),
		sendMail: (params: object) => post(`/email/api/email/send`, params),
		saveDraft: (params: object) => post(`/email/api/email/addDraft`, params),
		getDetail,
		emailWrite: (params: object) => post(`/email/api/email/emailWrite`, params),
		delete: (params: object) => post(`/email/api/email/del`, params),
		reply: (params: object) => post(`/email/api/email/reply`, params),
		addStarTarget: (params: object) => post(`/email/api/email/addStarTarget`, params),
		delStarTarget: (params: object) => post(`/email/api/email/delStarTarget`, params),
		moveItem: (params: object) => post(`/email/api/email/move`, params),
		unread: (params: object) => post(`/email/api/email/unread`, params),
		expression: (original: string) => get(`/email/api/openai/expression`, { original }),
		getSign: (account: string) => get(`/email/api/email/sign/${account}`),
		getBody: (id: string) => get(`/email/api/email/getBody/${id}`),
		download: (params: object) => get(`/email/api/email/download`, params),
		getUnreadNum: (account: string) => get(`/email/api/email/unreadNum/${account}`, {}),
		searchMsg: (data: any) => post(`/email/api/email/searchMsg`, data),
		searchEmailBox: (data: any) => post(`/email/api/email/searchEmailBox`, data),
		operParseAddress: (params: object) => get(`/email/api/openai/parseAddress`, params),
		getBillList: (params?: object) => get(`/system/api/customTo/getBillList`, params),
		getShipList: (params?: object) => get(`/system/api/customTo/getShipList`, params)
	},
	rule: {
		getList: (account: string) => get(`/email/api/config/list/${account}`, {}),
		addItem: (params: object) => post(`/email/api/config`, params),
		editItem: (params: object) => put(`/email/api/config`, params),
		changeStatus: (params: object) => post(`/email/api/config/changeStatus`, params),
		deleteItem: (id: string) => del(`/email/api/config/${id}`, {}),
		getItem: (id: string) => get(`/email/api/config/${id}`, {}),
	},
	client: {
		addClient: (params: object) => post(`/system/api/client`, params),
		updateClient: (params: object) => put(`/system/api/client`, params),
		getList: (params: object) => get(`/system/api/client/list`, params),
		getDetail: (id: string) => get(`/system/api/client/${id}`),
		delClient: (id: string) => del(`/system/api/client/${id}`),
		getClientInfo: (params: object) => get(`/system/api/client/info`, params),
	},
	inquiry: {
		addInquiry: (params: object) => post(`/system/api/inquiry`, params),
		updateInquiry: (params: object) => put(`/system/api/inquiry`, params),
		getList: (params: object) => get(`/system/api/inquiry/inquiryList`, params),
		isInquiry: (id: string) => get(`/system/api/inquiry/isInquiry`, { id }),
		delInquiry: (id: string) => del(`/system/api/inquiry/${id}`),
		getDocExtract: (id: string) => get(`/system/api/inquiry/docExtract`, { id }),
		getPlanList: (params: any) => get(`/system/api/inquiry/planList`, params),
		addPlan: (params: object) => post(`/system/api/inquiry/addPlan`, params),
		editPlan: (params: object) => put(`/system/api/inquiry/editPlan`, params),
		delPlan: (id: string) => del(`/system/api/inquiry/delPlan/${id}`),
		finishPlan: (id: string) => put(`/system/api/inquiry/finishPlan`, { id }),
		addProductCollect: (params: object) => post(`/system/api/productCollect/addProductCollect`, params),
		inquiryInfo: (id: string | number) => get(`/system/api/inquiry/info/${id}`),
	},
	template: {
		getList: (params: object) => get(`/email/api/template/list`, params),
		add: (params: object) => post(`/email/api/template`, params),
		edit: (params: object) => put(`/email/api/template`, params),
		del: (id: string) => del(`/email/api/template/${id}`),
	},
	factory: {
		getList: (params: object) => get(`/system/api/factory/list`, params),
		add: (params: object) => post(`/system/api/factory`, params),
		edit: (params: object) => put(`/system/api/factory`, params),
		del: (id: string) => del(`/system/api/factory/${id}`),
		getDetail: (id: string) => get(`/system/api/factory/${id}`),
	},
	offer: {
		getList: (params: object) => get(`/system/api/offer/list`, params),
		add: (params: object) => post(`/system/api/offer`, params),
		edit: (params: object) => put(`/system/api/offer`, params),
		del: (id: string) => del(`/system/api/offer/${id}`),
		getDetail: (id: string | number) => get(`/system/api/offer/${id}`),
		getFeTempList: () => get(`/system/api/pi/freightTemplate`),
		showPrice: (params: object) => get(`/system/api/offer/showPrice`, params),
	},
	pi: {
		getList: (params: object) => get(`/system/api/pi/list`, params),
		companyList: () => get(`/system/api/pi/companylist`),
		addOrUpdate: (params: object) => post(`/system/api/pi`, params),
		delPi: (id: string) => del(`/system/api/pi/${id}`),
		detail: (id: string) => get(`/system/api/pi/${id}`),
		piList: (params: object) => get(`/system/pi/piList`, params),
		exportPdf: (params: object) => post(`/system/api/pi/exportPdf`, params, { responseType: 'blob' }),
		emailAccountList: () => get(`/email/api/email/accountList`),
	},
	// 	联系人
	contact: {
		getList: (params: object) => get(`/email/api/friend/list`, params),
	},
	order: {
		getList: (params: object) => get(`/system/api/order/list`, params),
		add: (params: object) => post(`/system/api/order`, params),
		saveDraft: (params: object) => post(`/system/api/order/saveDraft`, params),
		edit: (params: object) => put(`/system/api/order`, params),
		info: (id: string) => get(`/system/api/order/${id}`),
		del: (ids: string) => del(`/system/api/order/${ids}`),
		queryList: (params: object) => get(`/system/api/productCollect/queryList`, params),
		inquiryAndOrderList: (params?: object) => get(`/system/api/inquiry/inquiryAndOrderList`, params),
		addPayment: (params: object) => put(`/system/api/order/addPayment`, params),
		settlePayment: (params: object) => put(`/system/api/order/settlePayment`, params),
		addRefund: (params: object) => put(`/system/api/order/addRefund`, params),
	},
	im: {
		getPurchaseer: (inquiryId: string) => get(`/system/api/inquiry/getPurchaseer/${inquiryId}`),
	},
	voucher: {
		// 认领凭证管理
		claim: (params: object) => put(`/system/api/voucher/claim`, params),
		// 获取凭证管理详细信息
		info: (id: string | number) => get(`/system/api/voucher/${id}`),
		// 列表
		getList: (params: object) => get(`/system/api/voucher/list`, params),
		// 取消认领
		cancel: (id: string) => del(`/system/api/voucher/cancel/${id}`),
	},
	cardApply: {
		// 新增信用卡刷卡申请
		add: (params: object) => post(`/system/api/cardApply`, params),
		// 修改信用卡刷卡申请
		edit: (params: object) => put(`/system/api/cardApply`, params),
		// 获取信用卡刷卡申请详细信息
		info: (id: string | number) => get(`/system/api/cardApply/${id}`),
		// 列表
		list: (params: object) => get(`/system/api/cardApply/list`, params),
		// 相似卡号列表
		listCards: (params: object) => get(`/system/api/cardApply/listCards`, params),
		// 删除
		del: (ids: string) => del(`/system/api/cardApply/${ids}`),
	},

};
